package com.pfzy.utildemo.views.dialog.base;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;

/**
 * 基础弹窗
 */
public abstract class UXBaseDialog extends Dialog {
    protected View mContentView;
    protected Context mContext;
    protected int mGravity;

    protected abstract View createContentView();

    public UXBaseDialog(@NonNull Context context, int gravity) {
        this(context, android.R.style.Theme_Holo_Dialog, gravity);
    }

    public UXBaseDialog(@NonNull Context context, int themeResId, int gravity) {
        super(context, themeResId);
        this.mContext = context;
        this.mGravity = gravity;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.mContentView = createContentView();
        Window window = getWindow();
        window.setGravity(this.mGravity);
        setContentView(this.mContentView);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = -1;
        params.height = -2;
        window.setAttributes(params);
    }
}
